import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { Cache } from "../../cache/Cache";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ScrollPolicy } from "../../../../flashx/textLayout/container/ScrollPolicy";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { FilterText } from "../../../../com/gengine/utils/FilterText";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SGuildPlan } from "../../../../Message/Game/SGuildPlan";
import { SGuildInfo } from "../../../../Message/Game/SGuildInfo";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GBitmap } from "../../../../com/mui/controls/GBitmap";
import { GTextArea } from "../../../../com/mui/controls/GTextArea";
import { GButton } from "../../../../com/mui/controls/GButton";
//class GuildStrategyPlanWindow
    
    export  class GuildStrategyPlanWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._dayArr = [Language.getString(57664), Language.getString(57665), Language.getString(57666), Language.getString(57667), Language.getString(57668), Language.getString(57669), Language.getString(57670)];
            this._dayTitleArr = [];
            this._dayPlanArr = [];
            this._lineArr_1 = [];
            this._lineArr_2 = [];
            this.setSize(475, 430);
            this.titleHeight = 28;
            this.title = Language.getString(57659);
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            var loc3=null;
            var loc6=null;
            var loc7=null;
            super.createDisposedChildrenImpl();
            var loc1=Cache.instance.guild.isLeader();
            this._bgUp = ObjCreate.createBg(17, 39, 440, 165, this);
            this._bgDown = ObjCreate.createBg(17, 208, 440, 210, this);
            this._sTitleBg = ObjCreate.createBg(16, 36, 445, 38, this, ImagesConst.RbListHeader);
            this._pTitleBg = ObjCreate.createBg(16, 205, 445, 38, this, ImagesConst.RbListHeader);
            this._sTxtBg = ObjCreate.createBg(25, 72, 425, 125, this, ImagesConst.RechargeBottom);
            this._pTxtBg = ObjCreate.createBg(25, 240, 425, 175, this, ImagesConst.RechargeBottom);
            var loc2=0;
            var loc4=30;
            var loc5=95;
            loc2 = 0;
            while (loc2 < 5) 
            {
                loc3 = ObjCreate.createBg(loc4, loc5, 415, 2, this, ImagesConst.SplitLine);
                loc5 = loc5 + 25;
                this._lineArr_1.push(loc3);
                ++loc2;
            }
            loc4 = 30;
            loc5 = 262;
            loc2 = 0;
            while (loc2 < 6) 
            {
                loc3 = ObjCreate.createBg(loc4, loc5, 415, 2, this, ImagesConst.SplitLine);
                loc5 = loc5 + 25;
                this._lineArr_2.push(loc3);
                ++loc2;
            }
            this._strategyTitle = ObjCreate.createGBitmap(null, 30, 45, this);
            this._planTitle = ObjCreate.createGBitmap(null, 30, 212, this);
            LoaderHelp.addResCallBack(ResFileConst.GuildStrategy, this.onResLoaded);
            this._strategyTxt = ObjCreate.createTextArea("", 25, 72, 425, 125, this);
            this._strategyTxt.textField.wordWrap = true;
            this._strategyTxt.maxChars = 200;
            this._strategyTxt.editable = loc1;
            this._strategyTxt.textField.defaultTextFormat = GlobalStyle.setTextFormatLeading(GlobalStyle.textFormat1, 12);
            this._strategyBtn = ObjCreate.createGButton(Language.getString(57661), 360, 43, 70, 25, this);
            this._strategyBtn.configEventListener(flash.events.MouseEvent.CLICK, this.onStrategyBtnClickHandler);
            this._strategyBtn.visible = loc1;
            this._planBtn = ObjCreate.createGButton(Language.getString(57663), 360, 212, 70, 25, this);
            this._planBtn.configEventListener(flash.events.MouseEvent.CLICK, this.onPlanBtnClickHandler);
            this._planBtn.visible = loc1;
            loc4 = 30;
            loc5 = 240;
            loc2 = 0;
            while (loc2 < this._dayArr.length) 
            {
                loc6 = ObjCreate.createGTextField(this._dayArr[loc2] + ":", loc4, loc5, 50, 20, this, GlobalStyle.textFormat6);
                (loc7 = ObjCreate.createTextArea("", loc4 + loc6.textWidth + 8, loc5, 380, 25, this)).verticalScrollPolicy = ScrollPolicy.OFF;
                loc7.maxChars = 30;
                loc7.editable = loc1;
                this._dayTitleArr.push(loc6);
                this._dayPlanArr.push(loc7);
                loc5 = loc5 + 25;
                ++loc2;
            }
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            var loc1=null;
            var loc2=null;
            var loc4=null;
            super.disposeImpl();
            this._bgUp.dispose();
            this._bgUp = null;
            this._bgDown.dispose();
            this._bgDown = null;
            this._sTitleBg.dispose();
            this._sTitleBg = null;
            this._pTitleBg.dispose();
            this._pTitleBg = null;
            this._strategyTitle.dispose();
            this._strategyTitle = null;
            this._planTitle.dispose();
            this._planTitle = null;
            this._strategyTxt.dispose();
            this._strategyTxt = null;
            this._strategyBtn.dispose();
            this._strategyBtn = null;
            this._planBtn.dispose();
            this._planBtn = null;
            this._sTxtBg.dispose();
            this._sTxtBg = null;
            this._pTxtBg.dispose();
            this._pTxtBg = null;
            var loc3=0;
            loc3 = 0;
            while (loc3 < this._dayTitleArr.length) 
            {
                loc1 = this._dayTitleArr[loc3];
                loc1.dispose();
                loc2 = this._dayPlanArr[loc3];
                loc2.dispose();
                loc1 = null;
                loc2 = null;
                ++loc3;
            }
            this._dayTitleArr.splice(0);
            this._dayPlanArr.splice(0);
            loc3 = 0;
            while (loc3 < 5) 
            {
                if (loc4 = this._lineArr_1[loc3]) 
                {
                    loc4.x = 0;
                    loc4.y = 0;
                    loc4.dispose();
                    loc4 = null;
                }
                ++loc3;
            }
            this._lineArr_2.splice(0);
            loc3 = 0;
            while (loc3 < 5) 
            {
                if (loc4 = this._lineArr_2[loc3]) 
                {
                    loc4.x = 0;
                    loc4.y = 0;
                    loc4.dispose();
                    loc4 = null;
                }
                ++loc3;
            }
            this._lineArr_2.splice(0);
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._strategyTitle.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildStrategyTitle);
            this._planTitle.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildPlanTitle);
            return;
        }

        /* internal  */onStrategyBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._strategyTxt.text;
            if (FilterText.instance.isHaveFilterTxt(loc1)) 
            {
                MsgManager.showRollTipsMsg(Language.getString(90136));
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildStrategyChange, loc1));
            }
            return;
        }

        /* internal  */onPlanBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc1=new SGuildPlan();
            var loc3=0;
            while (loc3 < this._dayPlanArr.length) 
            {
                loc2 = this._dayPlanArr[loc3];
                var loc4=loc3;
                switch (loc4) 
                {
                    case 0:
                    {
                        loc1.plan1 = loc2.text;
                        break;
                    }
                    case 1:
                    {
                        loc1.plan2 = loc2.text;
                        break;
                    }
                    case 2:
                    {
                        loc1.plan3 = loc2.text;
                        break;
                    }
                    case 3:
                    {
                        loc1.plan4 = loc2.text;
                        break;
                    }
                    case 4:
                    {
                        loc1.plan5 = loc2.text;
                        break;
                    }
                    case 5:
                    {
                        loc1.plan6 = loc2.text;
                        break;
                    }
                    case 6:
                    {
                        loc1.plan7 = loc2.text;
                        break;
                    }
                }
                ++loc3;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildPlanChange, loc1));
            return;
        }

        public updateGuildInfo(arg1: SGuildInfo): void
        {
            var loc2=null;
            if (this._strategyTxt) 
            {
                this._strategyTxt.htmlText = arg1.strategy;
            }
            var loc1=arg1.plan;
            var loc3=0;
            while (loc3 < this._dayPlanArr.length) 
            {
                loc2 = this._dayPlanArr[loc3];
                if (loc2 != null) 
                {
                    var loc4=loc3;
                    switch (loc4) 
                    {
                        case 0:
                        {
                            loc2.text = loc1.plan1;
                            break;
                        }
                        case 1:
                        {
                            loc2.text = loc1.plan2;
                            break;
                        }
                        case 2:
                        {
                            loc2.text = loc1.plan3;
                            break;
                        }
                        case 3:
                        {
                            loc2.text = loc1.plan4;
                            break;
                        }
                        case 4:
                        {
                            loc2.text = loc1.plan5;
                            break;
                        }
                        case 5:
                        {
                            loc2.text = loc1.plan6;
                            break;
                        }
                        case 6:
                        {
                            loc2.text = loc1.plan7;
                            break;
                        }
                    }
                }
                ++loc3;
            }
            return;
        }

        /* internal */ /* var */_bgUp: ScaleBitmap;

        /* internal */ /* var */_bgDown: ScaleBitmap;

        /* internal */ /* var */_strategyTitle: GBitmap;

        /* internal */ /* var */_sTitleBg: ScaleBitmap;

        /* internal */ /* var */_sTxtBg: ScaleBitmap;

        /* internal */ /* var */_strategyTxt: GTextArea;

        /* internal */ /* var */_planTitle: GBitmap;

        /* internal */ /* var */_pTitleBg: ScaleBitmap;

        /* internal */ /* var */_pTxtBg: ScaleBitmap;

        /* internal */ /* var */_strategyBtn: GButton;

        /* internal */ /* var */_planBtn: GButton;

        /* internal */ /* var */_dayArr: Array<any>;

        /* internal */ /* var */_dayTitleArr: Array<any>;

        /* internal */ /* var */_dayPlanArr: Array<any>;

        /* internal */ /* var */_lineArr_1: Array<any>;

        /* internal */ /* var */_lineArr_2: Array<any>;
    }
